<#include "portlet-layout.ftl"/>
<@layout>
<div ng-controller="AfficheCtrl">
    <table class="table table-striped table-hover table-condensed ng-cloak" style="width: 100%">
      <tbody>
        <tr ng-repeat="affiche in afficheList">
          <td>
            <span class="label label-info">{{affiche.typeDescr }}</span>&nbsp;&nbsp;<a href="${contextPath }/message/affiche/show.do?id={{affiche.id}}" target="_blank">{{affiche.title}}</a>
          </td>
          <td><small class="muted pull-right">{{affiche.updateDatetime | moment }}</small></td>
        </tr>
       </tbody>
     </table> 
     <div class="more-div" ng-click="showMore()"><@s.message code='btn.more' /> <i class="icon-chevron-down icon-large"></i></div>    
</div>       
<script type="text/javascript">
function AfficheCtrl($scope, $http, $filter) {
    $scope.afficheList = [];
    var pageIndex = 2;
    
    $http.post("${contextPath}/message/affiche/getTopN.json").success(function(data) {
      var afficheList = data.afficheList;
      for(i=0;i<afficheList.length;i++)
      {
        var affiche = afficheList[i];
        if(1==affiche.type)
            {
              affiche.typeDescr = "<@s.message code='dictparam.affiche-type.1' />"; 
            }
            else if(2==affiche.type)
            {
              affiche.typeDescr = "<@s.message code='dictparam.affiche-type.2' />"; 
            }
            else if(3==affiche.type)
            {
              affiche.typeDescr = "<@s.message code='dictparam.affiche-type.3' />"; 
            }
          }
          $scope.afficheList = afficheList;
        });
        
        $scope.showMoreAffiche = function(){
          $http.post("${contextPath}/message/affiche/getTopN.json", {"pageIndex": pageIndex}).success(function(data) {
            var afficheList = data.afficheList;
            if(0==afficheList.length)
            {
              $.webtools.notify({
                type: "notice",
                position: "center",
                delay: 1500,
                message: "<@s.message code='btn.more.nomore' />"     
              }); 
              return;
            }
            for(i=0;i<afficheList.length;i++)
            {
              var affiche = afficheList[i];
              if(1==affiche.type)
              {
                affiche.typeDescr = "<@s.message code='dictparam.affiche-type.1' />"; 
              }
              else if(2==affiche.type)
              {
                affiche.typeDescr = "<@s.message code='dictparam.affiche-type.2' />"; 
              }
              else if(3==affiche.type)
              {
                affiche.typeDescr = "<@s.message code='dictparam.affiche-type.3' />"; 
              }
              $scope.afficheList.push(affiche);
            }
            pageIndex++;
          }); 
       } 
}
</script>
</@layout>                 